<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of File
 *
 * @author chaporgin_a
 */
class VA_Form_FormElement_File extends VA_Form_FormElement {
    protected $storage = null;
    protected $public_id = null;
    public function setStorage(VA_Form_File_Storage $storage) {
        $this->storage = $storage;
        return $this;
    }
    /**
     *
     * @return VA_Form_File_Storage
     */
    public function getStorage() {
        return $this->storage;
    }

    public function setUploadedFile(VA_Form_File_TemporaryFile $file) {
        
        /* @var $v VA_Form_File_TemporaryFile */
        $v = $this->getValue();
        if( !empty ($v)) $v->remove();
        $v = new VA_Form_File_TemporaryFile($this->getStorage(), $place, null, $file->filename());
        $this->setValue($place);
        return $place;
    }
    protected function setDefaultDecorators() {
        $this->decorators = array();
        $this->addDecorator('ViewHelper')
                ->addDecorator('Error')
                ->addDecorator('HtmlTag', array('tag'=>'div', 'classes'=>array('element', 'file')))
                ->addDecorator('Label', array('position' => VA_Form_Decorator_Label::PREPEND))
                ->addDecorator('HtmlTag', array('tag'=>'div', 'jQueryMark'=>'controlWrapper', 'classes'=>array('elementWrapper')));
    }
    /**
     * Добавить значение
     * @param string $value
     */
    public function addValue(VA_Form_File_TemporaryFile $value){
        $this->value = $value;
    }

    public function getPrintableValue() {
        return $this->getValue()->getFilename();
    }
}

